package com.example.demo;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.example.pojo.CommonJSONResult;
import com.example.pojo.Resource;
import com.example.pojo.YMLResource;

@RestController
@RequestMapping("/hello")
public class HelloController {
	@Autowired
	private Resource resource;
	
	@Value("${com.hnust.opensource.name}")
	private String myName;
	@Value("${com.hnust.opensource.website}")
	private String mywebsite;
	@Value("${liuwj3.most.love}")
	private String mostLove;
	
	@Autowired
	private YMLResource ymlResource;
	
	@GetMapping("/getResource")
	public CommonJSONResult getResource() {
		Resource bean = new Resource();
		BeanUtils.copyProperties(resource, bean);
		
		return CommonJSONResult.ok(bean);
	}
	
	@GetMapping("/getYMLResource")
	public CommonJSONResult getYMLResource() {
		YMLResource bean = new YMLResource();
		BeanUtils.copyProperties(ymlResource, bean);
		
		return CommonJSONResult.ok(bean);
	}
	
	@GetMapping("/getYMLResource2")
	public CommonJSONResult getYMLResource2() {
		YMLResource bean = new YMLResource();
		bean.setName(myName);
		bean.setWebsite(mostLove);
		bean.setLanguage(mostLove);
		return CommonJSONResult.ok(bean);
	}
}
